#include "Projectile.h"

Projectile::Projectile(FireControl &fc, int x0, int y0, int type, int speed, float angle, int owner)
{
	this->fc = &fc;
	
	this->x0  	= x0;
	this->y0  	= y0;
	this->x  	= x0; 
	this->y 	= y0;
	this->type  = type;
	this->speed = speed;
	this->angle = ((angle*PI)/180); //muutos radiaaneihin
	this->velX 	= (speed * cos(this->angle)); //alkunopeudet
	this->velY 	= (speed * sin(this->angle)); //x ja y suuntiin
	this->time 	= 0; //kuinka kauan ammus on ollut ilmassa
	this->deltaTime = 0.4; //etenemisnopeus
	this->grav = GRAV; //ammukseen vaikuttava painovoima
	
	this->owner = owner;
	this->damage= 15;
	 
	pc = new ProjectileController(*this);
	
	
	//proju_01, proju_02, proju_03
	//g.loadImage(".//binaarit//proju_01.bmp",&projectileImg,0,255,0);
	projectileImg = g.getProju_01Img();
	imgObject = new ImageObject();
	imgObject->img =projectileImg;
	
	boundingBox = new SDL_Rect;
	clipRect.x = 0;
	clipRect.y = 0;
	clipRect.w = 6;
	clipRect.h = 6;
}

Projectile::~Projectile()
{
	//SDL_FreeSurface(projectileImg);
	delete imgObject;
	delete boundingBox;
	delete pc;
}

void Projectile::Explode(int objectID)
{	
	fc->removeProjectile(this,objectID);
}

ProjectileController* Projectile::getProjectileController()
{
	return pc;
}

SDL_Rect* Projectile::getBoundingBox()
{
	boundingBox->x = x;
	boundingBox->y = y;
	boundingBox->w = 6;
	boundingBox->h = 6;  
	return boundingBox;
}


ImageObject* Projectile::getImageObject()
{
	imgObject->leftUpperCorner.x = x;
	imgObject->leftUpperCorner.y = y;
		
	SDL_SetClipRect(projectileImg, &clipRect );
	
	/*else
		SDL_SetClipRect(vehicleImg, &cropRightDir );
	  */  
	return imgObject;
}
